package com.example.mo.service.UserServiceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.mo.Entity.User;
import com.example.mo.dao.UserMapper;
import com.example.mo.service.UserService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {


    @Override
    public List<User> findAll() {
        return baseMapper.selectList(null);
    }

    @Override
    public User login(String username, String password) {
        // 1. 根据用户名查询用户
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username", username);
        User user = baseMapper.selectOne(wrapper);

        // 2. 验证密码和账户状态
        if (user != null
            && password.equals(user.getPassword())
            && user.getIsActive() == 1) {
            return user;
        }
        return null;
    }


}
